
#include "nvdc.h"

void BQ25713_Init(void)
{
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_0,0x0E);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_0+1,0x07);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_1,0x10);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_1+1,0xE2);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_2,0xBF);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_2+1,0x32);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_3,0x34);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_CHARGE_OPTION_3+1,0x00);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_PROCHOT_OPTION_0,0x65);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_PROCHOT_OPTION_0+1,0x4A);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_PROCHOT_OPTION_1,0xFF);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_PROCHOT_OPTION_1+1,0x81);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_MAX_CHARGE_VOLTAGE+1,0x20);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_MAX_CHARGE_VOLTAGE,0xD0);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_INPUT_VOLTAGE+1,0x00);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_INPUT_VOLTAGE,0x14);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_MIN_SYSTEM_VOLTAGE+1,0x00);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_MIN_SYSTEM_VOLTAGE,0x18);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_IIN_HOST+1,0x1E);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_IIN_HOST,0x00);

    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_ADC_OPTION+1,0xFF);
    HUSB238_WriteReg(BQ25713_I2CAddress,BQ25713_REG_ADC_OPTION,0xA0);
}

void getChageState()
{
    uint8_t result=HUSB238_I2CReadBytes(BQ25713_I2CAddress,BQ25713_REG_CHARGER_STATUS+1);

    if(result&0x80)
    {
        sys_str.chargeState=1;
    }
    else
    {
        sys_str.chargeState=0;
    }
}
